using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Domain.Interfaces
{
    /// <summary>
    /// 权限路由映射仓储接口
    /// 支持动态路由权限映射的数据访问和管理
    /// </summary>
    public interface IPermissionRouteMappingRepository
    {
        /// <summary>
        /// 获取所有激活的路由映射（按优先级排序）
        /// </summary>
        Task<IEnumerable<PermissionRouteMapping>> GetActiveAsync();
        
        /// <summary>
        /// 获取所有路由映射（包括禁用的）
        /// </summary>
        Task<IEnumerable<PermissionRouteMapping>> GetAllAsync();
        
        /// <summary>
        /// 根据ID获取路由映射
        /// </summary>
        Task<PermissionRouteMapping?> GetByIdAsync(long id);
        
        /// <summary>
        /// 根据路径和方法查找匹配的映射
        /// </summary>
        Task<PermissionRouteMapping?> FindMatchingAsync(string path, string method);
        
        /// <summary>
        /// 批量获取匹配的映射（支持多个路径同时匹配）
        /// </summary>
        Task<IEnumerable<PermissionRouteMapping>> FindMatchingsAsync(IEnumerable<(string path, string method)> requests);
        
        /// <summary>
        /// 添加路由映射
        /// </summary>
        Task<long> AddAsync(PermissionRouteMapping mapping);
        
        /// <summary>
        /// 更新路由映射
        /// </summary>
        Task UpdateAsync(PermissionRouteMapping mapping);
        
        /// <summary>
        /// 删除路由映射
        /// </summary>
        Task DeleteAsync(long id);
        
        /// <summary>
        /// 批量删除路由映射
        /// </summary>
        Task BatchDeleteAsync(IEnumerable<long> ids);
        
        /// <summary>
        /// 根据分组获取映射
        /// </summary>
        Task<IEnumerable<PermissionRouteMapping>> GetByGroupAsync(string group);
        
        /// <summary>
        /// 获取所有分组列表
        /// </summary>
        Task<IEnumerable<string>> GetGroupsAsync();
        
        /// <summary>
        /// 检查路径模式是否存在冲突
        /// </summary>
        Task<bool> HasConflictAsync(string path, string method, long? excludeId = null);
        
        /// <summary>
        /// 批量导入映射
        /// </summary>
        Task<int> BatchImportAsync(IEnumerable<PermissionRouteMapping> mappings, bool replaceExisting = false);
        
        /// <summary>
        /// 导出映射为配置格式
        /// </summary>
        Task<string> ExportAsJsonAsync(string? group = null);
        
        /// <summary>
        /// 获取映射统计信息
        /// </summary>
        Task<(int total, int active, int groups)> GetStatisticsAsync();
    }
}
